import { defHttp } from "/@/utils/http/axios";

enum Api {
  updateUser='/system-service/user/profile/updateProfile',
  updateAccount='/system-service/user/profile/updateAccount',
  getUserInfo = '/system-service/user/profile/getUserBaseInfo',
  listTenant = '/system-service/user/profile/listTenant',
  changeTenantOwner = '/system-service/user/profile/changeTenantOwner',
  listTenantTree = '/system-service/user/profile/listTenantTree',
  exitUserTenant = '/system-service/tenantUser/exitTenant',
  updateUserPassword='/auth-service/localUser/resetPassword',

  pageAccessLog = '/system-service/accessLog/page',
  pageLoginLog = '/auth-service/loginLog/page',

  queryNameByCodes='/sys/position/queryByCodes',
  cancelApplyTenant = '/sys/tenant/cancelApplyTenant',
  getThirdAccountByUserId = '/sys/thirdApp/getThirdAccountByUserId',
  bindThirdAppAccount = '/sys/thirdApp/bindThirdAppAccount',
  deleteThirdAccount = '/sys/thirdApp/deleteThirdAccount',
  agreeOrRefuseJoinTenant = '/sys/tenant/agreeOrRefuseJoinTenant',
}

export const pageAccessLog = (params) => defHttp.get({ url: Api.pageAccessLog, params});
export const pageLoginLog = (params) => defHttp.get({ url: Api.pageLoginLog, params});


/**
 * 
 * @returns 获取当前登录用户所属租户
 */
export async function listTenant(params) {
  return defHttp.get({ url: Api.listTenant, params}, { isTransformResponse:false });
}

/**
 * 
 * @returns 获取当前登录用户所属租户
 */
export async function listTenantTree(accessToken?: string) {
  const headers = accessToken ? { 'Authorization': 'Bearer ' + accessToken } : {}
  return defHttp.get({ url: Api.listTenantTree, params: {}, headers}, { isTransformResponse:false });
}

/**
 * 用户编辑
 * @param params
 */
export const updateUser = (params) => {
  return defHttp.post({ url: Api.updateUser, params },{ isTransformResponse:false });
}

/**
 * 更新账户
 * @param params 
 * @returns 
 */
export const updateAccount = (params) => {
  return defHttp.post({ url: Api.updateAccount, params },{ isTransformResponse:false });
}


/**
 * 获取用户信息
 * @param params
 */
export const getUserInfo = () => {
  return defHttp.get({ url: Api.getUserInfo },{ isTransformResponse:false });
}

/**
 * 获取多个职务信息
 * @param params
 */
export const queryNameByCodes = (params) => {
  return defHttp.get({ url: Api.queryNameByCodes, params },{isTransformResponse:false});
}

/**
 * 修改密码
 * @param params
 */
export const updateUserPassword = (params) => {
  return defHttp.post({ url: Api.updateUserPassword, params },{isTransformResponse:false});
}

/**
 * 取消申请
 * @param params
 */
export const cancelApplyTenant = (params) => {
  return defHttp.put({ url: Api.cancelApplyTenant, data: params }, { joinParamsToUrl: true, isTransformResponse: false });
};

/**
 * 用户退出租户
 * @param params
 */
export const exitUserTenant = (params)=>{
  return defHttp.delete({ url: Api.exitUserTenant, params },{ isTransformResponse: false, joinParamsToUrl: true });
}

/**
 * 变更租户拥有者
 * @param params
 */
export const changeTenantOwner = (params)=>{
  return defHttp.post({ url: Api.changeTenantOwner, params },{ isTransformResponse: false, joinParamsToUrl: true });
}

/**
 * 获取账号第三方信息通过第三方类型
 * @param params
 */
export const getThirdAccountByUserId = (params) => {
  return defHttp.get({ url: Api.getThirdAccountByUserId, params }, { isTransformResponse: false });
};

/**
 * 根据第三方uuid绑定账号
 * @param params
 */
export const bindThirdAppAccount = (params) => {
  return defHttp.post({ url: Api.bindThirdAppAccount, params }, { isTransformResponse: false, joinParamsToUrl: true });
};

/**
 * 根据第三方uuid绑定账号
 * @param params
 */
export const deleteThirdAccount = (params) => {
  return defHttp.delete({ url: Api.deleteThirdAccount, params }, { isTransformResponse:false, joinParamsToUrl: true });
};

/**
 * 同意和拒绝加入租户
 * @param params
 */
export const agreeOrRefuseJoinTenant = (params) => {
  return defHttp.put({ url: Api.agreeOrRefuseJoinTenant, params },{ joinParamsToUrl: true });
};
